//
//  BLMeetGiftCell.m
//  Byelone
//
//  Created by Qi Liu on 2021/3/1.
//

#import "BLMeetGiftCell.h"
#import "BLMeetCollectionCell.h"
#import "UIView+BLView.h"
#import "BLGiftListView.h"
#define CCELL @"BLMeetCollectionCell"



@interface BLMeetGiftCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet BLGiftListView *giftListView;
@property (weak, nonatomic) IBOutlet UIView *botttomView;
@property (weak, nonatomic) IBOutlet UIImageView *leftGiftImageView;
@property (weak, nonatomic) IBOutlet UILabel *giftOwnLabel;
@property (weak, nonatomic) IBOutlet UIImageView *rightGiftIamgeView;
@property (weak, nonatomic) IBOutlet UIButton *donateBtn;
@property (nonatomic,strong) UICollectionViewFlowLayout * flowLayout;
@property (weak, nonatomic) IBOutlet UIView *baseView;

@end

@implementation BLMeetGiftCell

- (void)awakeFromNib {
    [super awakeFromNib];
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(70, 85);
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    [self.giftListView setCollectionViewLayout:layout];
    self.giftListView.showsHorizontalScrollIndicator = NO;
    self.giftListView.delegate = self;
    self.giftListView.dataSource = self;
    [self.giftListView registerNib:[UINib nibWithNibName:CCELL bundle:nil] forCellWithReuseIdentifier:CCELL];
    [self.giftListView reloadData];
    self.giftListView.bounces = NO;
    
    MJWeakSelf;
    self.giftListView.dataReload = ^{
        if (weakSelf.leftReload) {
            weakSelf.leftReload();
        }
        //左滑刷新
    };
    self.botttomView.layer.cornerRadius = 20;
    self.botttomView.layer.masksToBounds = YES;
    self.baseView.layer.cornerRadius = 5;
    self.baseView.layer.masksToBounds = YES;
   
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    [self.baseView setShadowRadius:16 color:BL_COLOR_PURPLE_L(0.12) offset:CGSizeMake(0, 4) opacity:1];
}



-(void)setGiftModel:(BLOrderOtherModel *)giftModel{
    _giftModel = giftModel;
    _dataArray = giftModel.list;
    self.giftOwnLabel.text = [NSString stringWithFormat:@"赠送%@个",BL_WTAPSTRING(giftModel.myselfGiftNum)];
    
    BOOL boy = [BLUserManager shareUser].baseInfo.gender == 1 ? YES:NO;
    UIImage * image = [UIImage imageNamed:boy ? @"my_beike":@"my_zhenzhu"];
    NSString * title = [NSString stringWithFormat:@"赠送%@",boy?@"贝壳":@"珍珠"];
    [self.donateBtn setTitle:title forState:UIControlStateNormal];
    self.leftGiftImageView.image = image;
    self.rightGiftIamgeView.image = image;
    
    
    [self.giftListView reloadData];
}


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _dataArray.count;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5, 0, 5, 0);
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    BLMeetCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CCELL forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:CCELL owner:nil options:nil]lastObject];
    }
    BLOtherItem * item = [_dataArray objectAtIndex:indexPath.item];
    cell.itemModel = item;
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    BLOtherItem * item = [_dataArray objectAtIndex:indexPath.item];
    if (_showInfo) {
        _showInfo(item);
    }
    
}

- (IBAction)donateCilck:(UIButton *)sender {
    if (_presentGift) {
        _presentGift();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
